

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import java.awt.Frame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JPasswordField;

import com.pernix.authen.model.AuthenResult;
public class LogOnDialog extends JDialog implements CommonSettings {//implements ActionListener 
	 JTextField txtUsername;
	 JPasswordField txtPassword;
	 JTextField txtIp;
	 JTextField txtPort;
	 JButton btnSubmit;
  public LogOnDialog(){
	this(null, "", "");
  }

  public LogOnDialog(ChatClient parent, String title, String message) {
    super(parent, title, true);
    if (parent != null) {
      Dimension parentSize = parent.getSize(); 
      Point p = parent.getLocation(); 
      setLocation(p.x + parentSize.width / 4, p.y + parentSize.height / 4);
    }
    
    JPanel panel = new JPanel();
    getContentPane().add(panel, BorderLayout.NORTH);
    
    JLabel username = new JLabel("Username");
    panel.add(username);
    
    txtUsername = new JTextField();
    txtUsername.setText("");
    txtUsername.setColumns(20);
    panel.add(txtUsername);
    JLabel password = new JLabel("Password");
    panel.add(password);
    
    txtPassword = new JPasswordField();
    txtPassword.setColumns(10);
    panel.add(txtPassword);
    txtPassword.setText("");
    JPanel Password = new JPanel();
    getContentPane().add(Password);
    
    JLabel ServerIp = new JLabel("SERVER IP");
    Password.add(ServerIp);
    
    txtIp = new JTextField();
    Password.add(txtIp);
    txtIp.setText("");
    txtIp.setColumns(18);
    JLabel Port = new JLabel("Port");
    Password.add(Port);
    
    txtPort = new JTextField();
    txtPort.setText("");
    Password.add(txtPort);
    txtPort.setColumns(10);
    JPanel buttonPane = new JPanel();
    btnSubmit = new JButton("submit"); 
    buttonPane.add(btnSubmit); 
    //btnSubmit.addActionListener(this);
    getContentPane().add(buttonPane, BorderLayout.SOUTH);
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    pack(); 
    //setVisible(true);
  }
  public void ShowDialog(){
	  setVisible(true);
  }
  public void addSubmitActionListener(ActionListener actionListener){
	  btnSubmit.addActionListener(actionListener);
  }
  public JButton getBtnSubmit(){
	  return btnSubmit;
  }
  
  public void actionPerformed(ActionEvent e) {
	 
    setVisible(false); 
    dispose(); 
    String username=txtUsername.getText();
	String password=txtPassword.getText();
	String ipserver=txtIp.getText();
	String port=txtPort.getText();
    
  /*
    System.out.println("username :"+username);
    System.out.println("password :"+password);
    System.out.println("ipserver :"+ipserver);
    System.out.println("port :"+port);
    */
  }
  
	public AuthenResult getAuthenResult(){
		AuthenResult result = new AuthenResult();
		result.setAuthenSuccess(true);
		result.setUsername("kookkai");
		result.setServerName("127.0.0.1");
		result.setPort("88888");
		return result; 
	}
	public void setErrorMessage(String msg){
		//System.out.println(msg);
		JOptionPane.showMessageDialog(null,msg);
	}
	
	@Override
	public void dispose() {
		//super.dispose();
		setVisible(false); 
		System.out.println("LogOn Dialog was closed.");
		
	}
}
